<!-- 物料 价格信息 -->
<template>
  <div class="clas_All">
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <el-form :model="AllotList" size="small" :inline="true">
            <el-form-item prop="">
              <el-input
                v-model="AllotList.foodCategoryName"
                placeholder="分类名称"
                clearable
              />
            </el-form-item>
            <el-form-item prop="">
              <el-input
                v-model="AllotList.foodCategoryCode"
                placeholder="分类编码"
                clearable
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" @click="getBase"
                >查询</el-button
              >
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                v-hasPermi="['bom:foodCategory:import']"
                size="mini"
                @click="getfoodCat"
                >更新菜品分类</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col>
        <el-table :data="tableData">
          <el-table-column label="序号" prop="id" align="center">
          </el-table-column>
          <el-table-column
            label="分类名称"
            prop="foodCategoryName"
            align="center"
          >
          </el-table-column>
          <el-table-column
            label="分类编码"
            prop="foodCategoryCode"
            align="center"
          >
          </el-table-column>
          <el-table-column label="状态" prop="flag" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.flag == 1">禁用</div>
              <div v-if="scope.row.flag == 0">启用</div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <!-- <el-button v-if="scope.row.flag == 0" @click="OpenFood(scope.row)"
                >启用</el-button
              >
              <el-button v-if="scope.row.flag == 1" @click="OpenFood(scope.row)"
                >禁用</el-button
              > -->
              <el-switch
                v-model="scope.row.flag1"
                active-color="#ff4949"
                inactive-color="#13ce66"
                @change="OpenFood(scope.row)"
              >
              </el-switch>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  getfoodType,
  getfoodCategory,
  foodCategoryimport,
} from "@/api/system/information";
export default {
  data() {
    return {
      AllotList: {},
      tableData: [],
    };
  },
  methods: {
    getBase() {
      getfoodType(this.AllotList).then((res) => {
        this.tableData = res.rows;

        this.tableData.filter((item, index) => {
          if (item.flag == 1) {
            this.tableData[index].flag1 = true;
          } else {
            this.tableData[index].flag1 = false;
          }
        });
      });
    },
    OpenFood(v) {
      let flag = v.flag;
      if (!v.flag1) {
        flag = 0;
      } else {
        flag = 1;
      }
      let obj = {
        id: v.id,
        flag,
      };
      getfoodCategory(obj).then((res) => {
        if (res.code == 200) {
          this.getBase();
        }
      });
    },
    getfoodCat() {
      foodCategoryimport().then((res) => {});
    },
  },
  created() {
    this.getBase();
  },
};
</script>

<style lang="scss" scoped>
.clas_All {
  margin: 20px;
}
</style>
